<!-- 授信管理--授信审核 -->
<template>
  <div>
    <PlusPage
      :columns="pageConfig"
      :table="{
        adaptive: true,
        hasIndexColumn: true,
        actionBar: { buttons, width: 140 },
      }"
      :default-page-info="{ pageSize: DEFAULT_PAGE_SIZE, page: 1 }"
      :request="getList"
    />
  </div>
</template>

<script lang="ts" setup>
import type { BasePageReq } from '@wlydfe/service'
import type { CreditlistModel } from '@/api/type'
import { getOptionLabel, priceToThousands } from '@wlydfe/core'
import { type PageInfo, type PlusColumn, useTable } from '@wlydfe/pro-ui'
import { omit } from 'lodash-es'
import { ref } from 'vue'
import { creditmanageApi } from '@/api'

//#region  -----------接口请求及参数-----------
const DEFAULT_PAGE_SIZE = 20
const queryParams = ref<BasePageReq<Partial<CreditlistModel>>>({
  currentPage: 1,
  pageLength: DEFAULT_PAGE_SIZE,
  countTotal: true,
  filterModel: {},
})

const getList = async (query: Partial<PageInfo> & Partial<CreditlistModel>) => {
  // 构造查询参数
  queryParams.value.currentPage = query.page ?? 1
  queryParams.value.pageLength = query.pageSize ?? DEFAULT_PAGE_SIZE
  queryParams.value.filterModel = omit(query, ['page', 'pageSize', 'value'])
  if (Array.isArray(query.createdDate)) {
    queryParams.value.filterModel.createdStartDate = query.createdDate[0]
    queryParams.value.filterModel.createdEndDate = query.createdDate[1]
    delete queryParams.value.filterModel.createdDate
  }
  const { succeed, model, total } = await creditmanageApi.getAuditPage(queryParams.value)
  return {
    data: succeed ? model : [],
    total: total ?? 0,
  }
}

//#region  -----------页面配置-----------
const pageConfig: PlusColumn[] = [
  {
    label: '授信编号',
    prop: 'applySn',
  },
  {
    label: '企业名称',
    prop: 'companyName',
    hideInSearch: false,
    order: 5,
  },
  {
    label: '金融机构',
    prop: 'financialInstitution',
    hideInSearch: false,
    order: 4,
  },
  {
    label: '金融产品',
    prop: 'financialProductType',
    hideInSearch: false,
    valueType: 'select',
    options: financialProductTypeOptions,
    render: (value, { row }) => {
      return row.financialProductType && row.financialInstitution === '南京银行股份有限公司'
        ? getOptionLabel(financialProductTypeOptions, value)
        : '-'
    },
    order: 3,
  },
  {
    label: '拟融资金额（元）',
    prop: 'applyLimit',
    render: value => {
      return priceToThousands(value)
    },
  },
  {
    label: '申请日期',
    prop: 'createdDate',
    hideInSearch: false,
    valueType: 'date-picker',
    fieldProps: {
      type: 'datetimerange',
      startPlaceholder: '开始时间',
      endPlaceholder: '结束时间',
      rangeSeparator: '至',
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    order: 1,
  },
  {
    label: '申请状态',
    prop: 'applyStatus',
    hideInSearch: false,
    valueType: 'select',
    options: creditapplyStatusOptions,
    order: 2,
  },
]
const { buttons } = useTable()
buttons.value = []
//#endregion
</script>
